'''
Created on Feb 4, 2012

@author: DavidDuncan
'''

class ItemsTable(object):
    '''
    Table class for each of the tables found in the Items Spreadsheet
    '''


    def __init__(self):
        '''
        Initalize the a table. 
        '''
        self.tabletype = "code"
        self.start = [0,0]
        self.end = [0,0]
        self.group = ""
        self.item_structure = ('code','description',
                               'brand','group','qty', 
                               'price')
        self.rows = [] 
        
    def defineItem(self,code=0,qty=0,description="",price=0.00,brand=""):
        '''
        @param code: string null o.k. 
        @param qty: integer null o.k. 
        @param description: string not null
        @param price: float price per pound not null
        @param brand: string null o.k.
        @return: dictionary item.    
        '''
        item = {}
        item['code'] = code
        item['qty'] = qty
        item['description'] = description
        item['price'] = price
        item['brand'] = brand 
        item['group'] = self.group
        return item 
    
    def defineRow(self,item):
        ''' Return the Item in list format
        @param item: dictionary
        @return: boolean false if the description is already in the table.   
        '''
        row = [
               item['code'],item['qty'],
               item['description'],item['price'],
               item['brand'], item['group']
               ]
        for row in self.rows: 
            if item['description'] == row[2]: 
                return False
        self.rows.append(row)
        return True
    
    

    